<template>
    <van-sticky>
        <van-nav-bar
            title="新增收货地址"
            left-text="返回"
            left-arrow
            @click-left="onBack"
        />
    </van-sticky>

    <van-address-edit
        :list="list"
        show-set-default
        :area-columns-placeholder="['请选择', '请选择', '请选择']"
        @save="onSave"
    />
</template>

<script setup>
import { areaList } from '@vant/area-data';
const { proxy } = getCurrentInstance();

const business = proxy.$business;

const onSave = async (values) =>
{
    let params = {
        busid:business.value.id,
        consignee:values.name,
        mobile:values.tel,
        code:values.areaCode,
        address:values.addressDetail,
        status:values.isDefault === true ? 1 : 0
    }
    
    let result = await proxy.$http.post({
        url:'/address/add',
        params
    });

    if(result.code === 1)
    {
        proxy.$success({
            message:result.msg,
            onClose:() =>
            {
                onBack();
            }
        });
    }else{
        proxy.$warning(result.msg);
    }
}

const onBack = () => proxy.$router.back();
</script>